
<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="UTF-8">
    <link href="/static/devtools30/layui/css/layui.css" rel="stylesheet" />
    <link href="/static/devtools30/css/devindexbase.css" rel="stylesheet" />
    <script src="/static/devtools30/js/jquery-1.11.2.min.js" type="text/javascript"></script>
    <script src="/static/devtools30/layui/layui.all.js" type="text/javascript"></script>
    <script src="/static/devtools30/js/devtoolCommon.js" type="text/javascript"></script>
    <title>新增元数据</title>
    <style>
        /*页面内边距*/

        .addwrap {
            padding: 30px 100px 30px 100px;
        }


        /*下拉框高度*/

        .addwrap .layui-input,
        .layui-select {
            height: 25px;
        }


        /*表单左边文本样式*/

        .addwrap .layui-form-label {
            padding: 0;
            text-align: left;
            height: 26px;
            line-height: 26px;
            width: 50px;
        }


        /*下拉框子项样式*/

        .addwrap .layui-form-select dl {
            top: 26px;
            padding: 0;
        }


        /*下拉框子项内容高度*/

        .addwrap .layui-form-select dl dd,
        .layui-form-select dl dt {
            line-height: 24px;
        }

        .addwrap .layui-input-block {
            min-height: 26px;
            margin-left: 35px;
        }


        /*复选框外边距*/

        .layui-form-item .layui-form-checkbox[lay-skin=primary] {
            margin-top: 0;
            margin-left: 64px;
        }

        .addwrap .layui-input-block {
            margin-left: 0;
        }


        /*多行文本框样式*/

        .layui-textarea {
            min-height: 50px;
        }

        .height26 .layui-form-item {
            height: 26px;
        }


        /*必填红色星号样式*/

        .layui-form-mid {
            line-height: normal!important;
        }
    </style>
</head>
<body>
<div class="addwrap">
    <div class="layui-form" lay-filter="form">
        <input type="hidden" name="id" id ="id" th:attr="value=${data.id}"/>
        <input type="hidden" name="formId" id ="formId"  th:attr="value=${formId}" />
        <div class="flex flex-align-center height26">
            <div class="layui-form-item flex flex-align-center">
                <label class="layui-form-label">序号</label>
                <div class="layui-input-inline marginleft10">
                    <!--验证 required lay-verify="required"-->
                    <input id="xh" name="xh" type="number" th:value="${data.xh}" onkeydown="DigitInput(this)" lay-verify="required" lay-reqtext="序号不能为空" autocomplete="off" class="layui-input">
                </div>
                <input type="checkbox" value="1" th:checked="${data.pkey eq 1} ? 'checked' :'false'" name="pkey" id="pkey" title="关键字" lay-skin="primary">
            </div>
        </div>
        <div class="flex flex-jusity-betreen flex-align-center height26">
            <div class="layui-form-item">
                <label class="layui-form-label">名称</label>
                <div class="layui-input-inline marginleft10">
                    <input type="text" name="fieldName" id="fieldName" th:value="${data.fieldName}" lay-verify="required" lay-reqtext="名称不能为空" placeholder="请输入名称" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux colorred">*</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">代码</label>
                <div class="layui-input-inline marginleft10">
                    <input type="text"  name="fieldCode" id="fieldCode" th:value="${data.fieldCode}" lay-verify="required" lay-reqtext="代码不能为空" placeholder="请输入代码" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux colorred">*</div>
            </div>
        </div>
        <div class="flex flex-jusity-betreen flex-align-center height26">
            <div class="layui-form-item">
                <label class="layui-form-label">类型</label>
                <div class="layui-input-inline marginleft10">
                    <select name="fieldType" id="fieldType" >
                        <option th:each="c : ${fieldtypesList}" th:value="${c.code}" th:text="${c.label}" >
                        </option>
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux colorred">*</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">长度</label>
                <div class="layui-input-inline marginleft10">
                    <input type="text"  name="typeLength" id="typeLength" th:value="${data.typeLength}" placeholder="请输入长度" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux colorred">*</div>
            </div>
        </div>
        <div class="flex flex-jusity-betreen flex-align-center height26">
            <div class="layui-form-item">
                <label class="layui-form-label">小数位</label>
                <div class="layui-input-inline marginleft10">
                    <input type="text"  th:value="${data.typeZeroLength}" name="typeZeroLength" id="typeZeroLength" placeholder="请输入小数位"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux colorred">*</div>
            </div>
        </div>

        <div class="flex flex-jusity-betreen flex-align-center height26" id="tableinfoDiv" style="display: none">
            <div class="layui-form-item">
                <label class="layui-form-label">父表</label>
                <div class="layui-input-inline marginleft10">
                    <select name="patienttable" id="patienttable" lay-filter="patienttable"  lay-search >
                        <option value=""></option>
                        <option th:each="c : ${metadataTableEntities}"  th:value="${c.id}" th:utext="${c.name} + ${c.code} ">
                        </option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">表字段</label>
                <div class="layui-input-inline marginleft10">
                    <select name="patienttablefield" id="patienttablefield"  lay-search>
                        <option value=""></option>
                    </select>
                </div>
            </div>
        </div>


        <div class="layui-form-item layui-form-text">
            <div class="marginbottom10">备注</div>
            <div class="layui-input-block">
                <textarea name="bz" id="bz"  placeholder="请输入备注" th:text="${data.bz}" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block flex flex-jusity-around tjbtn">
                <button class="layui-btn layui-btn-radius layui-btn-sm layui-btn-primary" onclick="closeWin()">取消</button>
                <button class="layui-btn layui-btn-radius layui-btn-sm " lay-submit="" lay-filter="save">保存</button>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    /*表单初始化*/
    $(function(){
        initEvent();
        layui.form.render('select');
    });



    layui.form.on('select(patienttable)', function (data) {
            $.getJSON("/DevtModelMetadataFieldController/getAll?tableid=" + data.value, function (data) {
                var optionstring = "";
                $.each(data.data, function (i, item) {
                    optionstring += "<option value=\"" + item.fieldCode + "\" >" + item.fieldName + " (" + item.fieldCode + ")" + "</option>";
                });
                $("#patienttablefield").html('<option value=""></option>' + optionstring);
                layui.form.render('select');
            });
    })

    function closeWin(){
        dlCommon.closeParentLayer();
    }
    function initEvent(){
        layui.form.on('submit(save)', function(data){
            saveData();
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        $("#fieldType option[value='[(${data.fieldType})]']").attr("selected", "selected");
        layui.form.render();
    }
    function saveData(){
        var data = layui.form.val('form');
        if(data.pkey==undefined){
            data.pkey=0;
        }
        try{
            data.typeLength=isNaN(parseInt(data.typeLength))?255:parseInt(data.typeLength);
        }catch(err){
            data.typeLength=255;
        }
        dlCommon.post("/DevtModelMetadataFieldController/save",data,function(res){
            if(!res.success){
                dlCommon.layerError(res.msg);
                return;
            }
            dlCommon.layerSuccess("保存成功",function(){
                parent.getFieldList();
                closeWin();
            })
        },true)
    }
</script>

</html>